<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .box {
        position: absolute;
        left: 0px;
        top: 0px;
      }
      .menu {
        width: 100px;
        height: 200px;
        background: white;
        border: 1px solid #000;
        position: absolute;
        /* display: none; */
      }
    </style>
  </head>
  <body>
    <div class="box">x:100px;y:100px</div>
    <div class="menu">
      <!-- <h1>刷新</h1> -->
    </div>
    <script>
      var boxEle = document.querySelector(".box");
      document.onmousemove = function (e) {
        var x = e.clientX;
        var y = e.clientY;
        console.log(x, y);
        boxEle.style.left = x + "px";
        boxEle.style.top = y + "px";
        boxEle.innerHTML = `x:${x}px;y:${y}px`;
      };
      var menuEle = document.querySelector(".menu");
      document.oncontextmenu = function (e) {
        var x = e.clientX;
        var y = e.clientY;
        menuEle.style.display = "block";
        menuEle.style.left = x + "px";
        menuEle.style.top = y + "px";
        e.preventDefault();
      };
      document.onclick = function () {
        menuEle.style.display = "none";
      };
    </script>
  </body>
</html>
